package com.franklin.java.utils;

import com.franklin.plugins.common.utils.DataCheckUtils;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * @author Franklin
 * @since 2021/2/5 17:15
 */
public class ThreadUtils {


    public static void runLater(@Nullable Project project, @Nullable String title, Runnable runnable) {
        if (DataCheckUtils.isEmpty(title)){
            title = "Franklin Java Data Helper";
        }
        ProgressManager.getInstance()
            .run(new Task.Backgroundable(project, title) {
                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    runnable.run();
                }
            });
    }
}
